-
Notifications
You must be signed in to change notification settings - Fork 57
Add differential testing harness #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Perhaps better DX is to have directories and just |
@Firestar99 FYI, I am going to revamp this a bit as it is a bit of a mess. |
FWIW, I am almost ready to update this. It is much cleaner now :-) |
2b484a8
to
4408a6e
Compare
I think this is ready for review. Sorry it is so big! I can break it down if need be. The main changes:
|
Another option we could do rather than binaries, is sort of what I did before (have built in harnesses which are configured) but mirror If I get my naga rust-gpu backend working, we could generate the rust-gpu code on the fly from the source |
This doubles CI time. I am sure there are things I can do to make CI faster (such as the deps_helper in compile test) but perhaps we should do that in followups? |
fe29d54
to
496a00d
Compare
I pulled out the In your previous rebase you forgot to move some of the new tests. I would like to fast-track that rename in #270 so it doesn't happen again. |
I really like the concept and I love that we can diff rust-gpu, wgsl and rust on cpu or whatever else we can think of. I've played around with it a bit and noticed a few things:
(continually adding to this) |
Yep, added text to that effect.
Yeah, I tried to match compiletest (they are called
Yes, I think we should. I was planning to do so in a followup. I wanted to keep this close to "as-is" so others can see where I just mirrored the existing comptiletest support. |
I'm working on the repeated runs, and noticed that there's some target_dir stomping going on. This is a clean run, and still the spirv-builder cargo run is marking crates that are supposedly clean as dirty: Running `tests/target/release/simple-compute-rust /tmp/.tmphUE36K`
Compiling compiler_builtins v0.1.138
Compiling core v0.0.0 (/home/firestar99/.rustup/toolchains/nightly-2024-11-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
Dirty proc-macro2 v1.0.94: the rustflags changed
Compiling proc-macro2 v1.0.94
Compiling libm v0.2.11
Dirty unicode-ident v1.0.18: the rustflags changed
Compiling unicode-ident v1.0.18
Dirty autocfg v1.4.0: the rustflags changed
Compiling autocfg v1.4.0
Compiling spirv-std-types v0.9.0 (/home/firestar99/workspace/frameworks/rust-gpu/crates/spirv-std/shared) |
We could provide pre-made binary crates that one can just drop files in for simple cases. I'd still want to keep the top-level "run |
This runs wgsl shaders and rust shaders and compares the output. If the output differs, the test fails. Differential testing is better than snapshot testing or golden file testing as there are no reference files to get outdated.
The stomping is happening cause spirv-builder can only find it's |
I have one concern about the design of this system: If we look at the main functions of |
I assumed any code being shared by more than 2 tests would be put into the difftest crate for reuse. The reason I did it this was was for maximum control (let's say you wanted different deps or different rustflags, of even different entries in cargo.toml). But it could definitely be collapsed into one. I'm indifferent, I just wanted to make sure we could test MxN scenarios |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be fine merging it as is, using it for a bit and see how it feels like. We can still refactor it later and adjust all our existing difftests as need arises.
Also tested my spirv-builder
patch with cargo-gpu, results in the exact same directory structure as before. I should mention though that I changed the type of target_dir
from String to PathBuf, but I'd wager noone apart from me is using that setting anyway.
The test harness compiles and runs Rust
shaders/kernels and compares the output with those produced by equivalent WGSL
shaders/kernels. Unlike traditional reference, golden, or snapshot tests—which check
against static outputs—differential testing compares multiple independent implementations of the same logic.
This approach is more robust because discrepancies between them are more likely to
indicate real bugs rather than issues with outdated reference files.
You can run difftests via
cargo difftest
. This is an alias set up in.cargo/config
for
cargo run --release -p difftest --
. You can filter to run specific tests bypassing the (partial) filenames to
cargo difftest some_file_name
.